<template>
  <div ref="echart" class="echart"></div>
</template>

<script>
export default {
  data() {
    return {
      echart: null
    }
  },
  mounted() {
    this.initDta()
  },
  methods: {
    initDta() {
      this.echart = this.$echarts.init(this.$refs.echart)
      const option = {
        title: {
          text: 'A类',
          bottom: '5',
          left: 'center',
          show: true,
          textStyle: {
            color: '#FFF',
            fontSize: 18, // 改变标示文字的大小
          },
        },
        tooltip: {
          trigger: 'item',
          formatter: `{b}：{c}艘次`
        },
        legend: {
          show: false,
        },
        series: [
          {
            type: 'pie',
            radius: ['55%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
            },
            label: {
              show: false,
              position: 'center',
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '20',
                fontWeight: 'bold',
                color: '#FFF',
                formatter: '{d}%',
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              { value: '1810', name: '其他', itemStyle: { color: '#0C3771' } },
              { value: '11827', name: 'A类', itemStyle: { color: '#8C5AE7' } },
            ],
          },
        ],
      }
      this.echart.setOption(option)
      this.echart.dispatchAction({
        type: 'highlight',
        dataIndex: 1,
      })
      // 监听鼠标滑入事件
      this.echart.on('mouseover', (e) => {
        this.echart.dispatchAction({
          type: 'downplay',
          seriesIndex: e.seriesIndex,
        })
        this.echart.dispatchAction({
          type: 'highlight',
          dataIndex: e.dataIndex,
        })
      })
      this.echart.on('mouseout', (e) => {
        this.echart.dispatchAction({
          type: 'downplay',
          seriesIndex: e.seriesIndex,
        })
        this.echart.dispatchAction({
          type: 'highlight',
          dataIndex: e.dataIndex,
        })
      })
    }
  }
}
</script>

<style scoped lang="less">
.echart {
  width: 100%;
  height: 100%;
}
</style>
